﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KingRoad.EPM.SafetyManagementEntity.Model;
using KingRoad.EPM.Web.Areas.SafetyConstruction.ViewModels;
using KingRoad.EPM.ProjectInfoEntity;

namespace KingRoad.EPM.Web.Areas.SafetyConstruction.Controllers
{
    public class ProjectSupervisionController : BaseController
    {
        /// <summary>
        /// 总监办
        /// </summary>
        /// <returns></returns>
        public ActionResult List(string uId, string uName, string uSection)
        {
            ViewBag.uId = uId;
            ViewBag.uName = uName;
            ViewBag.uSection = uSection;
            int totalRecord = 0;
            //当前页码
            ViewBag.pageNum = 1;
            //每页多少条
            ViewBag.numPerPage = 10;
            var segmentList = ProjectSupervisionUIRule.GetListForPage(ViewBag.pageNum, ViewBag.numPerPage, "SUPERVISION_ID", out totalRecord, "");
            //总条数
            ViewBag.totalcount = totalRecord;
            //总页数
            ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;

            return View(new ProjectSupervisionViewModel { ProjectSupervisionList = segmentList });
        }
        /// <summary>
        /// 总监办(分页提交)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SplitPage()
        {
            ViewBag.uId = Request.Form["uId"];
            ViewBag.uName = Request.Form["uName"];
            ViewBag.uSection = Request.Form["uSection"];
            int totalRecord = 0;
            //当前页码
            ViewBag.pageNum = Convert.ToInt32(Request.Form["pageNum"]);
            //每页多少条

            ViewBag.numPerPage = Convert.ToInt32(Request.Form["numPerPage"]);
            ViewBag.iput_deName = Request.Form["iput_deName"];
            string sql = " 1=1 ";
            if (ViewBag.iput_deName != "")
                sql += " and SUPERVISION_DEPARTNAME like '%" + ViewBag.iput_deName + "%' ";
            var segmentList = ProjectSupervisionUIRule.GetListForPage(ViewBag.pageNum, ViewBag.numPerPage, "SUPERVISION_ID", out totalRecord, sql);
            //总条数
            ViewBag.totalcount = totalRecord;
            //总页数
            ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;
            return View("List", new ProjectSupervisionViewModel { ProjectSupervisionList = segmentList });
        }

    }
}
